<template>
  <div @keyup.enter="getData()">
    <el-form class="query-table-form" :inline="true">
      <el-form-item>
        <el-input v-model="params.customer_name" placeholder="主体名称查询" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="params.corp_name" placeholder="负责人查询" :clearable="true"></el-input>
      </el-form-item>
      <el-form-item>
        <select-address
          v-model="params.address_code"
          placeholder="地址查询"
          auto-top
          clearable
          @change="getData()"
        ></select-address>
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" @click="getData()">查询</el-button>
      </el-form-item>
      <el-form-item>
        <el-button
          icon="el-icon-download"
          :loading="exportLoading"
          @click="exportExcel('联保受理（已拒绝）')"
        >
          导出
        </el-button>
      </el-form-item>
    </el-form>
    <c-table border v-loading="loading" :columns="tableColumns" :data="tableData">
      <template v-slot:address="scope">
        <div class="text-truncate" :title="scope.row.address">{{ scope.row.address }}</div>
      </template>
      <template v-slot:itemStatus="scope">
        <span class="badge" :class="`badge-${scope.row.itemStatusStyle}`">
          {{ scope.row.itemStatusLabel }}
        </span>
      </template>
    </c-table>
    <div class="query-pagination">
      <div></div>
      <el-pagination
        layout="total, prev, pager, next, jumper"
        :current-page.sync="params.index"
        :page-size="params.size"
        :total="totalCount"
        @current-change="getData"
      ></el-pagination>
    </div>

    <el-dialog
      :visible.sync="reportVisible"
      :close-on-click-modal="false"
      :before-close="handleCreditClose"
      append-to-body
      top="30px"
      width="80%"
    >
      <el-tabs>
        <el-tab-pane label="数字档案卡">
          <credit-file :query-id="queryId" :viewMode="viewMode"></credit-file>
        </el-tab-pane>
        <el-tab-pane label="政府推荐函">
          <recommend-file :related-data="relatedData" :viewMode="true"></recommend-file>
        </el-tab-pane>
        <el-tab-pane label="附件">
          <attach-view :queryId="queryId" :visible="reportVisible"></attach-view>
        </el-tab-pane>
      </el-tabs>
    </el-dialog>
    <attach-cmpt :visible.sync="attachVisible" :customer-related-id="attachRelatedId"></attach-cmpt>
    <reject-view :visible.sync="approvalVisible" :reject-data="editRow"></reject-view>
  </div>
</template>

<script>
import SelectAddress from '@/components/select/SelectAddress'
import { enumGuatype, enumIsApprovalGuaStatus } from '@/credit/plugins/enumTown'
import CreditFile from '@/credit/components/creditFile/CreditCard'
import AttachView from '@/credit/components/AttachView'
import RecommendFile from '@/credit/views/city/program/RecommendFile'
import AttachCmpt from '@/credit/views/city/program/Attach'
import RejectView from '@/credit/views/city/program/RejectView'
import taskTableMixin from '@/credit/mixin/mission/taskTable'
export default {
  components: {
    SelectAddress,
    AttachView,
    CreditFile,
    RecommendFile,
    AttachCmpt,
    RejectView,
  },
  mixins: [taskTableMixin],
  data() {
    return {
      enumGuatype,
      enumIsApprovalGuaStatus,
      order: {
        confuse_time: 'desc',
      },
      params: {
        index: 1,
        size: 15,
        'gua_type.eq': '1',
        'is_approval_gua.eq': '2',
        'item_status.eq': '1',
        'service_id.eq': '',
        address_code: '',
        customer_name: '',
        corp_name: '',
      },
      reportVisible: false,
      relatedData: {},
      attachVisible: false,
      attachRelatedId: '',
      queryId: '',
      viewMode: false,
      tableName: 'customer_related',
      tableData: [],
      tableColumns: [
        {
          attrs: { label: '项目名称', prop: 'customer_name', minWidth: '110px' },
          process: (v, row) => ({
            attrs: { class: 'project-history', attrs: { 'data-history': row.is_history } },
          }),
        },
        { attrs: { label: '业务类型', prop: 'gua_type_label', align: 'center' } },
        { attrs: { label: '地址', prop: 'address' }, slot: 'address' },
        { attrs: { label: '负责人', prop: 'corp_name', align: 'center' } },
        { attrs: { label: '联系电话', prop: 'mobile_no', align: 'center', width: 120 } },
        { attrs: { label: '申请金额(万元)', prop: 'apply_funds', align: 'center' } },
        { attrs: { label: '拒绝时间', prop: 'confuse_time', width: 140 } },
        { attrs: { label: '拒绝角色', prop: 'confuse_person', align: 'center' } },
        {
          attrs: { label: '项目状态', prop: 'itemStatusLabel', align: 'center' },
          slot: 'itemStatus',
        },
        {
          attrs: { label: '操作', align: 'center', width: 150 },
          operations: [
            { content: '拒绝详情', icon: 'fa fa-times-circle-o', event: this.handleEdit },
            { content: '上传附件', icon: 'fa fa-clipboard', event: this.hanleAttach },
            { content: '查看', icon: 'fa fa-search', event: this.handleEditReport },
          ],
        },
      ],
      approvalVisible: false,
      editRow: {},
    }
  },
  computed: {},
  watch: {},
  mounted() {},
  created() {
    this.getData()
  },
  methods: {
    handleEdit(row) {
      this.approvalVisible = true
      this.editRow = { ...row }
    },
    hanleAttach(row) {
      this.attachVisible = true
      this.attachRelatedId = row.customer_related_id
    },
    handleView(row) {
      this.queryId = row.customer_related_id
      this.viewMode = false
      this.reportVisible = true
    },
    handleEditReport(row) {
      this.queryId = row.customer_related_id
      this.viewMode = true
      this.relatedData = row
      this.reportVisible = true
    },
    dataAdapter(item) {
      item.gua_type_label = enumGuatype[item.gua_type]
      item.confuse_time = this.$utils.dateFormat(item.confuse_time, this.dateFmt)
      const itemStatus = enumIsApprovalGuaStatus[item.is_approval_gua] || {}
      item.itemStatusLabel = itemStatus.label
      item.itemStatusStyle = itemStatus.css

      return item
    },
    handleCreditClose() {
      this.reportVisible = false
      if (this.viewMode) {
        return
      }
      this.getData(this.params.index)
    },
  },
}
</script>
<style lang="scss" scoped></style>
